using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;

namespace MoEngine
{
    public class Camera : SceneNode
    {
        #region View Matrix
        Matrix m_ViewMatrix;

        public Matrix ViewMatrix
        {
            get
            {
                return m_ViewMatrix;
            }
        }

        public void LookAt(Vector3 pos, Vector3 target, Vector3 up)
        {
            m_ViewMatrix = Matrix.CreateLookAt(pos, target, up);
        }

        #endregion

        #region Projection Matrix

        Matrix m_ProjMatrix;

        float m_FieldOfView;
        public float FieldOfView
        {
            get { return m_FieldOfView; }
            set { m_FieldOfView = value; UpdateProjMatrix(); }
        }

        float m_AspectRatio;
        public float AspectRatio
        {
            get { return m_AspectRatio; }
            set { m_AspectRatio = value; UpdateProjMatrix(); }
        }

        float m_NearPlane;
        public float NearPlane
        {
            get { return m_NearPlane; }
            set { m_NearPlane = value; UpdateProjMatrix(); }
        }

        float m_FarPlane;
        public float FarPlane
        {
            get { return m_FarPlane; }
            set { m_FarPlane = value; UpdateProjMatrix(); }
        }


        public Matrix ProjMatrix
        {
            get
            {
                return m_ProjMatrix;
            }
        }


        public void SetProjection(float fieldOfView, float aspectRatio, float nearPlaneDist, float farPlaneDist)
        {
            m_FieldOfView = fieldOfView;
            m_AspectRatio = aspectRatio;
            m_NearPlane = nearPlaneDist;
            m_FarPlane = farPlaneDist;

            UpdateProjMatrix();
        }

        protected void UpdateProjMatrix()
        {
            m_ProjMatrix = 
                Matrix.CreatePerspectiveFieldOfView(
                m_FieldOfView, m_AspectRatio, m_NearPlane, m_FarPlane);
        }

        #endregion

        #region Constructor

        public Camera()
            : base()
        {
            SetProjection(MathHelper.PiOver4, 4f / 3f, 1f, 10000f);
        }

        #endregion
    }
}
